import sun.font.FontRunIterator;

import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();

        //读取建筑
        int[][] buildings = new int[n][4];
        for (int i = 0; i < n; i++) {
            buildings[i][0] = scanner.nextInt();// 石灰
            buildings[i][1] = scanner.nextInt();// 砂岩
            buildings[i][2] = scanner.nextInt();// 花岗岩
            buildings[i][3] = scanner.nextInt();// 收益
        }

        //dp
        int[][][] dp = new int[A+1][B+1][C+1];
        //初始化
        for (int i = 0; i < A; i++) {
            for (int j = 0; j < B; j++) {
                for (int k = 0; k < C; k++) {
                    dp[i][j][k] = Integer.MIN_VALUE;
                }
            }
        }
        dp[0][0][0] = 0;

        for (int i = 0; i < n; i++) {
            int a = buildings[i][0];
            int b = buildings[i][1];
            int c = buildings[i][2];
            int v = buildings[i][3];

            for (int x = A; x >= a ; x--) {
                for (int y = B; y >= b ; y--) {
                    for (int z = C; z >= c; z--) {
                        if(dp[x -a][y-b][z -c]  != Integer.MIN_VALUE){
                            dp[x][y][z] = Math.max(dp[x][y][z] ,dp[x -a][y-b][z -c]+v);
                        }
                    }
                }
            }
        }
        //max
        int max = 0;
        for (int i = 0; i <= A ; i++) {
            for (int j = 0; j <= B ; j++) {
                for (int k = 0; k <= C ; k++) {
                    max = Math.max(max,dp[i][j][k]);
                }
            }
        }
        System.out.println(max);
    }
}
